package org.example.service.impl;

import org.example.annotation.IAutowired;
import org.example.annotation.IService;
import org.example.annotation.ITransactional;
import org.example.annotation.MyContext;
import org.example.dao.AccountDao;
import org.example.pojo.Account;
import org.example.service.TransferService;

@IService("transferService")
@ITransactional
public class TransferServiceImpl implements TransferService {


    // 最佳状态
    @IAutowired
    private AccountDao accountDao;

    // 构造函数传值/set方法传值

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        MyContext.printMap();

        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(to);
        int c = 1 / 0;
        accountDao.updateAccountByCardNo(from);
    }
}
